﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class userControls_LimitMovieList : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int genre = 0;
            switch (this.ID)
            {
                case "comedy":
                    genre = 4;
                    break;
                case "thriller":
                    genre=7;
                    break;
                case "action":
                    genre=6;
                    break;
                case "animation":
                    genre=9;
                    break;
                case "drama":
                    genre=11;
                    break;
                case "mistery":
                    genre=8;
                    break;
                case "horror":
                    genre=5;
                    break;
                case "romance":
                    genre=10;
                    break;
                case "doc":
                    genre = 12;
                    break;
                case "promo":
                    genre = 0;
                    break;
                case "free":
                    genre = 1;
                    break;
                case "new":
                    genre = 2;
                    break;
                case "top":
                    genre = 3;
                    break;
                case "pop":
                    genre = 13;
                    break;

                default:
                    Response.Redirect("Ooops.aspx");
                    break;
            }
            populateControls(genre);
        }
    }

    private void populateControls(int genre)
    {
        switch (genre)
        {
            case 0:
                list.DataSource = MovieAccess.GetPromoMovies();
                list.DataBind();
                break;
            case 1:
                list.DataSource = MovieAccess.GetFreeMovies();
                list.DataBind();
                break;
            case 2:
                list.DataSource = MovieAccess.GetNewMovies();
                list.DataBind();
                break;
            case 3:
                list.DataSource = MovieAccess.GetTopMovies();
                list.DataBind();
                break;
            case 13:
                list.DataSource = MovieAccess.GetPopularMovies();
                list.DataBind();
                break;
            default:
                list.DataSource = MovieAccess.GetMoviesInGenreHomePage(genre, 0);
                list.DataBind();
                break;
        }    
    }
}